package com.flute.framework.data;

import com.flute.framework.FluteMonitor;
import com.flute.framework.data.constants.Constants;
import com.flute.framework.index.IDocumentBuilder;
import com.flute.framework.util.EventLoggerUtil;
import com.flute.tools.data.DataRecord;

public class RecordValidator {
	public static boolean isValidSingerDataRecord(DataRecord record) {
		if (record == null) {
			EventLoggerUtil
					.info("DataRecord不能为空", FluteMonitor.getImporterKey());
			return false;
		}

		if (!record.containsField(IDocumentBuilder.DOCUMENT_ID)) {
			EventLoggerUtil.info("DataRecord的DocumentId不能为空", FluteMonitor
					.getImporterKey());
			return false;
		}

		return true;
	}

	public static boolean isValidDataRecord(DataRecord record) {
		if (isValidSingerDataRecord(record)) {
			if (!record.containsField(IDocumentBuilder.ACTIVITY_FIELD)) {
				EventLoggerUtil.info("DataRecord的Activaty_field不能为空",
						FluteMonitor.getImporterKey());
				return false;
			}
		}

		return true;
	}

	public static void handleFieldToNewField(DataRecord dataRecord,
			String field, String newField) {
		if (dataRecord.containsField(field)) {
			String value = dataRecord.getFieldValue(field);
			dataRecord.deleteField(field);
			dataRecord.AddField(newField, value);
		} else {
			dataRecord.AddField(newField, Constants.EMPTY);
		}
	}
}
